<?php

namespace addons\sum\console;

use addons\sum\console\Command;
use app\admin\model\sum\Game as GameModel;
use app\admin\model\sum\GameRank as GameRankModel;
use think\Db;
use Exception;
use think\console\Input;
use think\console\Output;
use think\Queue;

class SumGameRank extends Command
{
    protected $input = null;
    protected $output = null;

    /**
     * 帮助命令配置
     */
    protected function configure()
    {
        $this->setName('sum:game_rank')
            ->setDescription('sum 游戏排行榜统计');
    }

    /*
     * 逻辑处理
     */
    protected function execute(Input $input, Output $output)
    {
        //逻辑处理
        $list=GameModel::where('status','normal')->select();
        foreach ($list as $item){
            $data = [
                'game_id' => $item['id'],
                'game_type' => $item['type'],
                'views_rank' => $item['views_rank'],
                'sales_rank' => $item['sales_rank'],
                'statdate' =>  date("Y-m-d", time()),
                'createtime' => time(),
            ];
            $datas[] = $data;
        }
        GameRankModel::insertAll($datas);
        $output->writeln("done");
    }

}
